<aside class="sidebar">
    <div class="widget widget-categories">
        <h3 class="widget-title"><?php _e('分类', 'text-domain'); ?></h3>
        <ul class="category-list">
            <?php 
            $args = array(
                'hide_empty' => false,
                'parent' => 0
            );
            $categories = get_categories($args);
            
            foreach ($categories as $category) {
                echo '<li class="category-item">';
                echo '<a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a>';
                
                // 获取二级分类
                $child_args = array(
                    'hide_empty' => false,
                    'parent' => $category->term_id
                );
                $child_categories = get_categories($child_args);
                
                if ($child_categories) {
                    echo '<ul class="subcategory-list">';
                    foreach ($child_categories as $child_category) {
                        echo '<li class="subcategory-item">';
                        echo '<a href="' . get_category_link($child_category->term_id) . '">' . $child_category->name . '</a>';
                        echo '</li>';
                    }
                    echo '</ul>';
                }
                
                echo '</li>';
            }
            ?>
        </ul>
    </div>
    
    <?php dynamic_sidebar('sidebar-1'); ?>
</aside>
